﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Yatagan.IoC.IoCElements;

namespace Yatagan.IoC
{
    public class Current
    {
        #region Singleton

        private Current() { }

        private readonly static Current _current = new Current();

        public static Current Instance
        {
            get { return _current; }
        }

        #endregion

        internal Components IoCComponents { get; set; }

        public void Load(Configuration.Elements.IoC ioc)
        {
            IoCComponents = new Components();

            foreach (Configuration.Elements.Component component in ioc.Compoenents)
            {
                ObjectCreationType objectCreationType = (ObjectCreationType)Enum.Parse(typeof(ObjectCreationType), component.Creation);
                Type serviceType = Yatagan.Library.ObjectCreator.GetObjectType(component.ServiceType);
                Type typeType = Yatagan.Library.ObjectCreator.GetObjectType(component.TypeType);

                Component objectComponent = new Component { ObjectCreationType = objectCreationType, ServiceType = serviceType, TypeType = typeType };

                IoCComponents.Add(serviceType, objectComponent);
            }
        }
    }
}
